package com.freeter.modules.article.controller;

import java.util.Arrays;

import com.freeter.common.validator.ValidatorUtils;
import com.freeter.datasources.DataSourceNames;
import com.freeter.datasources.annotation.DataSource;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.freeter.common.utils.JQPageInfo;
import com.freeter.common.mpextend.parser.ParseWrapper;
import com.freeter.common.utils.PageInfo;


import com.freeter.modules.article.entity.NcCmsArticleClassEntity;
import com.freeter.modules.article.entity.view.NcCmsArticleClassView;
import com.freeter.modules.article.entity.model.NcCmsArticleClassModel;

import com.freeter.modules.article.service.NcCmsArticleClassService;
import com.freeter.common.utils.PageUtils;
import com.freeter.common.utils.R;
import com.freeter.common.utils.MPUtil;



/**
 * cms文章分类表
 * 后端接口
 * @author xuchen
 * @email 171998110@qq.com
 * @date 2019-08-13 16:46:33
 */
@RestController
@RequestMapping("article/nccmsarticleclass")
@SuppressWarnings({"unchecked","rawtypes"})
public class NcCmsArticleClassController {
    @Autowired
    private NcCmsArticleClassService ncCmsArticleClassService;

    /**
     * 列表
     */
    @RequestMapping("/page")
    @RequiresPermissions("article:nccmsarticleclass:list")
    public PageUtils page(JQPageInfo jqPageInfo,NcCmsArticleClassModel ncCmsArticleClass){
        EntityWrapper< NcCmsArticleClassEntity> ew = ParseWrapper.parseWrapper(ncCmsArticleClass);
     	PageInfo pageInfo = new PageInfo(jqPageInfo);
     	PageUtils page = ncCmsArticleClassService.queryPage(pageInfo, ew);
    
        return page;
        
    }

	/**
     * 列表
     */
    @RequestMapping("/list")
    @RequiresPermissions("article:nccmsarticleclass:list")
    public R list( NcCmsArticleClassModel ncCmsArticleClass){
       	EntityWrapper< NcCmsArticleClassEntity> ew = ParseWrapper.parseWrapper(ncCmsArticleClass);
        return R.ok().put("data",  ncCmsArticleClassService.selectListView(ew));
    }

	 /**
     * 查询
     */
    @RequestMapping("/query")
    @RequiresPermissions("article:nccmsarticleclass:info")
    public R query(NcCmsArticleClassEntity ncCmsArticleClass){
        EntityWrapper< NcCmsArticleClassEntity> ew = ParseWrapper.parseWrapper(ncCmsArticleClass);
		NcCmsArticleClassView  ncCmsArticleClassView =  ncCmsArticleClassService.selectView(ew);
		return R.ok("查询cms文章分类表成功").put("data",  ncCmsArticleClassView);
    }
	
    /**
     * 信息
     */
    @RequestMapping("/info/{classId}")
    @RequiresPermissions("article:nccmsarticleclass:info")
    public R info(@PathVariable("classId") Integer classId){
        NcCmsArticleClassEntity ncCmsArticleClass = ncCmsArticleClassService.selectById(classId);

        return R.ok().put("ncCmsArticleClass", ncCmsArticleClass);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    @RequiresPermissions("article:nccmsarticleclass:save")
    public R save(@RequestBody NcCmsArticleClassEntity ncCmsArticleClass){
    	ValidatorUtils.validateEntity(ncCmsArticleClass);
        ncCmsArticleClassService.insert(ncCmsArticleClass);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    @RequiresPermissions("article:nccmsarticleclass:update")
    public R update(@RequestBody NcCmsArticleClassEntity ncCmsArticleClass){
        ValidatorUtils.validateEntity(ncCmsArticleClass);
        ncCmsArticleClassService.updateAllColumnById(ncCmsArticleClass);//全部更新
        
        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    @RequiresPermissions("article:nccmsarticleclass:delete")
    public R delete(@RequestBody Integer[] classIds){
        ncCmsArticleClassService.deleteBatchIds(Arrays.asList(classIds));

        return R.ok();
    }

}
